package com.tedu.ivos.application.controller;

import com.tedu.ivos.application.pojo.dto.AppQuery;
import com.tedu.ivos.application.pojo.dto.AppSaveFormParam;
import com.tedu.ivos.application.pojo.vo.AppVO;
import com.tedu.ivos.application.service.IAppService;
import com.tedu.ivos.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/app")
public class AppController {
    @Autowired
    IAppService appService;

    @PostMapping("save")
    public JsonResult save(AppSaveFormParam appSaveFormParam) {
        log.debug("新增申请单，参数：{}", appSaveFormParam);
        appService.saveApp(appSaveFormParam);
        return JsonResult.ok();
    }

    @GetMapping("select")
    public JsonResult select(AppQuery appQuery) {
        log.debug("查询申请单，参数：{}", appQuery);
        List<AppVO> list = appService.select(appQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("cancel")
    public JsonResult cancel(Long id) {
        log.debug("撤销申请单：参数={}", id);
        appService.cancel(id);
        return JsonResult.ok();
    }

    @PostMapping("/distribute/{applicationId}/{vehicleId}")
    public JsonResult distribute(@PathVariable Long applicationId, @PathVariable Long vehicleId) {
        log.debug("分配车辆：参数={}，{}", applicationId, vehicleId);
        appService.distribute(applicationId, vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("/backVehicle/{id}/{vehicleId}")
    public JsonResult backVehicle(@PathVariable Long id, @PathVariable Long vehicleId) {
        log.debug("还车：参数={}，{}", id, vehicleId);
        appService.backVehicle(id, vehicleId);
        return JsonResult.ok();
    }
}